<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/4/21
 * Time: 10:05
 */

namespace app\admin\controller;

use think\Db;
use think\Request;

class Agreement extends Base
{
    /**
     * 注销须知
     * @return mixed|\think\response\Json
     */
    public function logout(){
        if(Request::instance()->isPost()){
            $other_logout = trim(input('logout'), ' ');
            $res = Db::table('up_other')->where('other_id', 3)->setField('other_logout', $other_logout);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $logout = Db::table('up_other')->where('other_id', 3)->value('other_logout');
        return $this->fetch('agreement/logout', ['logout' => $logout]);
    }
    
    /**
     * 用户服务协议
     * @return mixed|\think\response\Json
     */
    public function userAgreement(){
        if(Request::instance()->isPost()){
            $agreement = trim(input('agreement'), ' ');
            $res = Db::table('up_other')->where('other_id', 1)->setField('other_user_agreement', $agreement);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $user_agreement = Db::table('up_other')->where('other_id', 1)->value('other_user_agreement');
        return $this->fetch('agreement/useragreement', ['agreement' => $user_agreement]);
    }
    
    /**
     * 用户隐私协议
     * @return mixed|\think\response\Json
     */
    public function ysAgreement(){
        if(Request::instance()->isPost()){
            $agreement = trim(input('agreement'), ' ');
            $res = Db::table('up_other')->where('other_id', 2)->setField('other_ys_agreement', $agreement);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $ys_agreement = Db::table('up_other')->where('other_id', 2)->value('other_ys_agreement');
        return $this->fetch('agreement/ysagreement', ['agreement' => $ys_agreement]);
    }
}